//
// Created by lihengliu on 2023/2/26.
//
#include "jni_map_util.h"

jclass JNIMapUtil::createHashMapClass(JNIEnv *env) {
    const char *clazz_name = "java/util/HashMap";
    jclass class_map = env->FindClass(clazz_name);
    return class_map;
}

jobject JNIMapUtil::createHashMapInstance(JNIEnv *env) {
    jclass class_map = createHashMapClass(env);
    jmethodID init_map = env->GetMethodID(class_map, "<init>", "()V");
    jobject obj_map = env->NewObject(class_map, init_map);
    return obj_map;
}

jmethodID JNIMapUtil::createHashMapPutMethod(JNIEnv *env) {
    return env->GetMethodID(createHashMapClass(env), "put",
                            "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
}

jmethodID JNIMapUtil::createHashMapPutMethod(JNIEnv *env, jclass clazz) {
    return env->GetMethodID(clazz, "put",
                            "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
}

jmethodID JNIMapUtil::createHashMapGetKeyMethod(JNIEnv *env) {
    jclass class_map_entry = env->FindClass("java/util/Map$Entry");
    return env->GetMethodID(class_map_entry, "getKey", "()Ljava/lang/Object;");
}

jmethodID JNIMapUtil::createHashMapGetKeyMethod(JNIEnv *env, jclass class_map_entry) {
    return env->GetMethodID(class_map_entry, "getKey", "()Ljava/lang/Object;");
}

jmethodID JNIMapUtil::createHashMapGetValueMethod(JNIEnv *env) {
    jclass class_map_entry = env->FindClass("java/util/Map$Entry");
    return env->GetMethodID(class_map_entry, "getValue", "()Ljava/lang/Object;");
}

jmethodID JNIMapUtil::createHashMapGetValueMethod(JNIEnv *env, jclass class_map_entry) {
    return env->GetMethodID(class_map_entry, "getValue", "()Ljava/lang/Object;");
}
